package com.examp.dy.dy.controller;

import com.examp.dy.dy.dao.BookRepository;
import com.examp.dy.dy.dao.UserRepository;
import com.examp.dy.dy.entities.Accounts;
import com.examp.dy.dy.entities.Book;
import com.examp.dy.dy.entities.User;
import com.examp.dy.dy.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping("/user")
    public String displayuser(Model model){
        List<User> users = userService.getAll();
        model.addAttribute("Users",users);
        return "/main/personal information";
    }
    @GetMapping("/adduser")
    public String displayuserForm(Model model){
        User Buser=new User();
        model.addAttribute("user",Buser);
        return "/security/registerUser";
    }
    @GetMapping("/borrow1")
    public String displayborrow1(Model model,@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){
        PageHelper.startPage(pageNum,4);
//        List<Book_Time> employees = employeeService.getAll();
//        PageInfo<Book_Time> pageInfo = new PageInfo<>(employees);
//        model.addAttribute("pageInfo",pageInfo);
        return "/main/borrowing information";
    }
    @GetMapping("/updateUser")
    public String update(@RequestParam("id") long userId, Model model){
        User theUser=userService.findByuserId(userId);
        model.addAttribute("user",theUser);
        return "/security/registerUser";
    }
    @GetMapping("/borrow2")
    public String displayborrow2(Model model,@RequestParam(defaultValue = "2",value = "pageNum") Integer pageNum){
        PageHelper.startPage(pageNum,4);
//        List<Book_Time> employees = employeeService.getAll();
//        PageInfo<Book_Time> pageInfo = new PageInfo<>(employees);
//        model.addAttribute("pageInfo",pageInfo);
        return "/main/borrowing information2";
    }


}
